package com.qf.ems.controller;

import com.qf.ems.entity.Emp;
import com.qf.ems.service.EmpService;
import com.qf.ems.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/manage/safe/insertEmp")
public class InsertEmpController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1 获取新增用户相关的参数:name,salary,age
        String name = req.getParameter("name");
        String salary = req.getParameter("salary");
        String age = req.getParameter("age");
        //2 调用service方法进行用户新增
        EmpService empService = new EmpServiceImpl();
        Emp emp = new Emp();
        emp.setName(name);
        emp.setSalary(Double.valueOf(salary));
        emp.setAge(Integer.valueOf(age));
        empService.addEmp(emp);
        //3 返回响应，跳转到用户详情页面
        resp.sendRedirect(req.getContextPath()+"/manage/safe/showAllEmp");
    }
}
